package com.hinnotek.amoeba.ui.activity.old

import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import com.lee.common.base.BaseActivity
import com.hinnotek.amoeba.R
import com.hinnotek.amoeba.bean.old.AmibaPayByAmibaPayIdBean
import com.hinnotek.amoeba.databinding.ActivityPaymentRequestDetailAmoebaBinding
import com.hinnotek.amoeba.dialog.CustomDialog
import com.hinnotek.amoeba.utilities.ToastUtils
import com.hinnotek.amoeba.viewmodels.AmibaPayViewModel
import com.lee.common.network.net.ObserverState
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class PaymentRequestDetailAmoebaActivity :
    BaseActivity<ActivityPaymentRequestDetailAmoebaBinding>() {

    val viewModel by viewModels<AmibaPayViewModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setLeftVisible(true)
        setTitle("付款申请")

        setContentView(R.layout.activity_payment_request_detail_amoeba)
    }

    override fun initVew() {
    }

    override fun setData() {
        val amibaPayId = intent.getIntExtra("amibaPayId", 0)
        getAmibaPayByAmibaPayId(amibaPayId)
    }

    /**
     * app端查询单个付款申请详情接口
     */
    fun getAmibaPayByAmibaPayId(amibaPayId: Int) {
        val customDialog = CustomDialog(mContext, "正在加载...")
        customDialog.show()

        viewModel.getAmibaPayByAmibaPayId(amibaPayId)
            .observe(this, object : ObserverState<AmibaPayByAmibaPayIdBean>() {
                override fun onDataChange(data: AmibaPayByAmibaPayIdBean) {
                    bindingView.tvPaymentType.text = if (data.amibaPayType == 1) "产品" else "项目"
                    if (data.amibaPayType == 1) {
                        bindingView.tvPaymentChooseUnit.visibility = View.GONE
                        bindingView.tvPaymentChooseProject.text = data.provideProjectName
                    } else {
                        bindingView.llPaymentChooseUnit.visibility = View.VISIBLE
                        bindingView.tvPaymentChooseProject
                        bindingView.tvPaymentChooseUnit.text = data.customerName
                        bindingView.tvPaymentChooseProject.text = data.projectName
                    }
                    bindingView.tvPaymentHopeDate.text = data.payDate
                    bindingView.tvPaymentCause.text = data.payOverview
                    bindingView.tvPaymentTotal.text = data.payTotal
                    bindingView.tvPaymentApplicant.text = data.createUser
                    bindingView.tvPaymentApprover.text = data.approvalUser
                    when (data.approvalState) {
                        1 -> {
                            bindingView.tvApproverStatus.text = "已申请"
                            bindingView.tvApproverStatus.setTextColor(getColor21(R.color.black))
                        }
                        2 -> {
                            bindingView.tvApproverStatus.text = "已同意"
                            bindingView.tvApproverStatus.setTextColor(getColor21(R.color.xui_btn_green_normal_color))
                        }
                        3 -> {
                            bindingView.tvApproverStatus.text = "已拒绝"
                            bindingView.tvApproverStatus.setTextColor(getColor21(R.color.xui_config_color_red))
                        }
                    }
                    bindingView.tvPaymentCc.text = data.sendUser
                    super.onDataChange(data)
                }

                override fun onError(msg: String?, code: Int) {
                    customDialog.dismiss()
                    ToastUtils.showShort(mContext, msg)
                    super.onError(msg, code)
                }
            })


    }
}